Skip to content

feat(tree): 项目树与提交文件树支持紧凑显示单一子文件夹链 - #257

Merged
xiaoyumuxi merged 2 commits into
mainfrom
feat/2641-compact-folders
Dec 3, 2026
Merged

xiaoyumuxi merged 2 commits into
mainfrom
feat/2641-compact-folders

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

关联 Issue:1lck/Lithe-IDEA#2641(树层级太深,单一子文件夹自动折叠)

类型:feat

改动

参照 IntelliJ IDEA 的 “Compact Middle Packages” 和 VS Code 的 explorer.compactFolders:只含一个子文件夹的文件夹和它的子文件夹显示成一行,名称用 / 连接(例如 main/java/com)。分隔符只用 /;Java 包的 . 写法属于语言知识,应由插件负责,Core 和宿主都不处理。

workspace.projectTree.rows

  • 请求新增可选字段 compact;节点新增可选字段 folder(是文件夹)和 listed(宿主已列出子项)。
  • 开启 compact 后,满足以下条件的文件夹和唯一的子文件夹共用一行:不是根、已经列出、唯一的已加载子项是文件夹。这一行是链上的最后一个文件夹。
  • 响应新增 heads,每行一个值,表示链首(链上第一个文件夹)在 nodes 里的位置;行是否展开只看链首的 open。
  • 响应新增 depths,每行一个值,表示这一行的缩进层级:节点 depth 减去它上面与唯一子文件夹合并的文件夹数。一条链不管多长只占一层,链下的文件和文件夹跟着少缩进。
  • 选区或 top 落在链中的文件夹上时,移到这条链所在的行,并用 selectionMoved 标出。
  • 未列出的文件夹会截断链,宿主在链首展开时补列行文件夹,链会逐步合并。
  • 不传 compact 时行为不变,响应里也没有 heads 和 depths。

git.changedFileGroups

  • 请求新增可选字段 nest: { compact? }。开启后,变更文件的所有上级文件夹(包括自身没有文件的)都会按原顺序列出,每项新增 depth(第几层文件夹行)和 label(这一行显示的文字)。
  • compact: true 时,不是顶层、自身没有文件、只含一个文件夹的文件夹会被省略,它的行交给子文件夹,label 用 / 连接整条链。
  • 不传 nest 时输出不变,depth 和 label 都不出现。以前宿主 Go 端负责拼中间文件夹和计算深度(appendFolders),这部分树投影改由 Core 负责。

其他

  • rust/fixtures/workspace/project-tree-rows-v1.json 新增 6 个用例(含链套链的缩进层级),rust/fixtures/git/changed-file-groups-v1.json 新增 3 个用例。
  • rust/contracts/rust-core-api.md 补充了两个命令的新字段。
  • 顺手修复了 crates/project/src/name_ranking.rs 在 Rust 1.100 下的 clippy::question_mark(feat(search): support qualified symbol matching in workspace.rankNames and workspace.symbolQuery #255 引入)。只要 lithe-core 在受影响列表里,这个问题就会让 clippy 失败。

验证

  • cargo test -p lithe-core -p lithe-project -p lithe-git -p lithe-project-tree:全部通过(lithe-core 975 个)
  • cargo clippy -p lithe-git -p lithe-project-tree -p lithe-project -p lithe-core --all-targets -- -D warnings:通过
  • scripts/rust-core/verify-rust-core-comments.sh、node scripts/rust-core/verify-platform-tests.mjs:通过

桌面端接入在 Lithe-IDEA 的配套 Draft PR 中(会临时固定本 PR 的 head)。

- workspace.projectTree.rows 新增可选 compact:已列出、只含一个子文件夹的非根文件夹与子文件夹合成一行(同 IDEA/VS Code),返回 heads 给出每行链首;选区与 top 落在链中文件夹时移到该行。
- git.changedFileGroups 新增可选 nest{compact}:按树列出全部上级文件夹并给出 depth 与 label,compact 时把无文件且只含一个文件夹的链合并,label 用 / 连接。
- 两个 fixture 增加对应用例,rust-core-api.md 补充契约。
- 顺手修 name_ranking.rs 的 clippy question_mark(#255 引入)。

Refs 1lck/Lithe-IDEA#2641
紧凑链无论多长只占一层缩进;链下的文件和文件夹要跟着少缩进。workspace.projectTree.rows 在 compact 时多返回 depths,每行一个:节点 depth 减去它上面与唯一子文件夹合并的文件夹数。补一个链套链的 fixture。
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review December 3, 2026 06:04
@xiaoyumuxi
xiaoyumuxi merged commit 5dfe797 into main Dec 3, 2026
7 of 9 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

Comment on lines +198 to 203
let row = row_path(path)
.or_else(|| ancestors(path).find_map(&row_path))
.unwrap_or_default();
if row != path {
selection.selected = Some(row.to_string());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Compacted folder marks resist toggling

When a marked folder joins its only child, row_path moves the selection to the child but leaves the mark behind. Toggle matches exact paths, so Cmd/Ctrl-clicking the compact row again leaves the folder in the batch.

Learn more

The project tree and row-selection contracts use row paths as selection identities. When a chain forms, the project tree changes the visible row path to the last folder but retains the original mark and anchor because the original folder is still loaded. Toggle and Extend use exact row paths, so Toggle adds the last folder instead of removing the original mark, and Extend cannot use an anchor at the start of a visible chain. Batch targets suppress a marked descendant when its ancestor is still marked, leaving the original folder in the batch.

Example: Cmd/Ctrl-click the unlisted src folder, then expand it to discover its only child, src/main. Cmd/Ctrl-click the resulting src/main row to unmark it. The reducer instead retains src and adds src/main, and the batch still targets src.

Recommended fix: Use the compact row mapping for mark and anchor matching as well as for focus. If batch targets must retain the original filesystem paths, keep that identity separate and remove its mark when the corresponding visible row is toggled off. Add a fixture that carries the selection from a toggle through a listing that forms a chain and into a second toggle.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant